package com.delivery.deliverysystem.controller;


import com.delivery.deliverysystem.common.ServerResponse;
import com.delivery.deliverysystem.dao.ClientMapper;
import com.delivery.deliverysystem.pojo.DO.Client;
import com.delivery.deliverysystem.pojo.DO.Product;
import com.delivery.deliverysystem.pojo.DO.ProductCategory;
import com.delivery.deliverysystem.pojo.VO.ClientVO;
import com.delivery.deliverysystem.pojo.VO.ProductNameVO;
import com.delivery.deliverysystem.pojo.VO.ProductVO;
import com.delivery.deliverysystem.service.ClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品类别控制类
 */
@RestController
@RequestMapping("/client")
@Api(tags = "客户资料接口")
public class ClientController {
    @Autowired
    private ClientService clientService;

    @PostMapping("/createClient")
    @ApiOperation(value = "创建客户资料",response = ServerResponse.class,httpMethod = "POST")
    public ServerResponse createClient(@RequestBody Client client){
        boolean i = clientService.createClient(client);
        if(i) return ServerResponse.createBySuccess("创建成功");
        return ServerResponse.createByError("创建失败");
    }
    @PostMapping("/updateClient")
    @ApiOperation(value = "修改客户资料",response = ServerResponse.class,httpMethod = "POST")
    public ServerResponse updateClient(@RequestBody Client client){
        boolean i = clientService.updateClient(client);
        if(i) return ServerResponse.createBySuccess("更新成功");
        return ServerResponse.createByError("更新失败");
    }
    @PostMapping("/deleteClient")
    @ApiOperation(value = "删除客户资料",response = ServerResponse.class,httpMethod = "POST")
    public ServerResponse deleteClient(@RequestParam String id){
        boolean b = clientService.removeById(id);
        if(b) return ServerResponse.createBySuccess("删除成功");
        return ServerResponse.createByError("删除失败");
    }
    @GetMapping("/getClientList")
    @ApiOperation(value = "获取全部客户资料",response = ServerResponse.class,httpMethod = "GET")
    public ServerResponse getClientList(){
        List<ClientVO> clientList = clientService.getClientList();
        if(clientList!=null && !clientList.isEmpty()) return ServerResponse.createBySuccess(clientList);
        return ServerResponse.createBySuccess("客户资料列表为空");
    }
    @GetMapping("/getClientStatusList")
    @ApiOperation(value = "获取全部启用的产品资料",response = ServerResponse.class,httpMethod = "GET")
    public ServerResponse getClientStatusList(){
        List<ClientVO> clientList = clientService.getClientStatusList();
        if(clientList!=null && !clientList.isEmpty()) return ServerResponse.createBySuccess(clientList);
        return ServerResponse.createBySuccess("客户资料列表为空");
    }
    @GetMapping("/getClientById")
    @ApiOperation(value = "根据id查询产品资料",response = ServerResponse.class,httpMethod = "GET")
    public ServerResponse getClientById(@RequestParam String id){
        Client client = clientService.getClientById(id);
        if(client==null) return ServerResponse.createByError("客户不存在");
        return ServerResponse.createBySuccess(client);
    }

    @GetMapping("/getClientByName")
    @ApiOperation(value = "根据名称查询产品资料",response = ServerResponse.class,httpMethod = "GET")
    public ServerResponse getClientByName(@RequestParam String name){
        List<Client> clientByName = clientService.getClientByName(name);
        if(clientByName==null) return ServerResponse.createByError("客户不存在");
        return ServerResponse.createBySuccess(clientByName);
    }

    @GetMapping("/searchClient")
    @ApiOperation(value = "根据名称模糊查询产品资料",response = ServerResponse.class,httpMethod = "GET")
    public ServerResponse searchClient(@RequestParam String name){
        List<Client> clients = clientService.searchClient(name);
        if(clients!=null && !clients.isEmpty()) return ServerResponse.createBySuccess(clients);
        return ServerResponse.createBySuccess("客户资料列表为空");
    }


}
